package com.aiton.bamin.bamindaijiadrier.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aiton.bamin.bamindaijiadrier.R;
import com.aiton.bamin.bamindaijiadrier.constant.Constant;
import com.aiton.bamin.bamindaijiadrier.model.SendOrder;
import com.iarcuschin.simpleratingbar.SimpleRatingBar;

public class OrderDetailActivity extends ZjbBaseActivity implements View.OnClickListener {

    private TextView mTv_time;
    private TextView mTv_state;
    private TextView mTv_start;
    private TextView mTv_end;
    private TextView mTv_fee;
    private TextView mTv_finalprice;
    private TextView mTv_pingjia;
    private SimpleRatingBar mRatingbar_pingfeng;
    private TextView mTv_no_pingjia;
    private LinearLayout mLine_pingjia;
    //    private PingLun.DatasBean pinglunDatas;
    private TextView mTv_orderId;
    private String mMode;
    private View mLine_cancel_cause;
    private TextView mTv_cancel_cause;
    private TextView mTv_order_mileage;
    private LinearLayout mLine_pingjia_content;
    private SendOrder mData;
    private TextView mTv_fee_money;
    private TextView mTv_order_mileage_money;
    private TextView mTv_order_waiting_time;
    private TextView mTv_order_waiting_time_money;
    private TextView mTv_comfirm_toll_money;
    private TextView mTv_order_other_money;
    private LinearLayout mLine_price;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        showLoadingDialog();
        init();
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void initViews() {
        mTv_time.setText("下单时间：" + mData.getOrderTime());
        mTv_state.setText("订单状态：" + mData.getOrderStatus());
        mTv_start.setText(mData.getStartLocation());
        mTv_end.setText(mData.getEndLocation());
        mTv_fee_money.setText(mData.getFee() + "元");
        mTv_orderId.setText("订单号：" + mData.getId());
        mTv_order_mileage.setText("里程(" + mData.getMileage() + "公里)");


        Double mileageCost = mData.getMileageCost();
        mTv_order_mileage_money.setText((mileageCost == null) ? 0 + "元" : mileageCost + "元");


        Integer waitTime = mData.getWaitTime();
        mTv_order_waiting_time.setText("等待费用(" + (waitTime == null ? 0 : waitTime) + "分钟)");
        mTv_order_waiting_time_money.setText(mData.getWaitTimeFee() + "元");

        Double tollFees = mData.getTollFees();
        mTv_comfirm_toll_money.setText(((tollFees == null) ? 0 : tollFees) + "元");

        mTv_order_other_money.setText(mData.getOtherFees() + "元");
        Double finalPrice = mData.getFinalPrice();
        if (finalPrice != null) {
            mTv_finalprice.setText(finalPrice + "");
        } else {
            mTv_finalprice.setText(0 + "");
        }

        if (mData.getOrderStatus().equals("完成")) {
            mLine_pingjia.setVisibility(View.VISIBLE);
            mLine_pingjia_content.setVisibility(View.VISIBLE);
            mTv_no_pingjia.setVisibility(View.GONE);
            mLine_cancel_cause.setVisibility(View.GONE);


            Double score = mData.getScore();
            double s = 5;
            if (score != null) {
                s = score;
            }
            mRatingbar_pingfeng.setRating((float) s);
            String comment = mData.getComment();
            if (comment != null && !TextUtils.isEmpty(comment)) {
                mTv_pingjia.setText(comment);
            } else {
                mTv_pingjia.setText("无评价信息");
            }
        } else if (mData.getOrderStatus().equals("取消")) {
            mLine_pingjia.setVisibility(View.GONE);
            mTv_no_pingjia.setVisibility(View.GONE);
            mLine_cancel_cause.setVisibility(View.VISIBLE);
            mLine_price.setVisibility(View.GONE);
            if (mData.getCancelCause() != null) {
                if (!TextUtils.isEmpty(mData.getCancelCause())) {
                    Log.e("OrderDetailActivity", "initViews: --->>" + mData.getCancelCause().length());
                    String cancelCause = mData.getCancelCause();
                    if (cancelCause.length() == 6) {
                        String replace = cancelCause.replace("，", "").replace("。", "");

                        mTv_cancel_cause.setText(replace);
                    }else{
                        mTv_cancel_cause.setText(cancelCause);

                    }
                } else {
                    mTv_cancel_cause.setText("无");
                }
            }

        } else if (mData.getOrderStatus().equals("未评价")) {
            mLine_pingjia.setVisibility(View.VISIBLE);
            mLine_pingjia_content.setVisibility(View.GONE);
            mTv_no_pingjia.setVisibility(View.VISIBLE);
            mLine_cancel_cause.setVisibility(View.GONE);

        } else {
            mLine_pingjia.setVisibility(View.GONE);
            mLine_pingjia_content.setVisibility(View.GONE);
            mTv_no_pingjia.setVisibility(View.VISIBLE);
            mLine_cancel_cause.setVisibility(View.GONE);
        }
        cancelLoadingDialog();
    }

    @Override
    protected void setListeners() {
        findViewById(R.id.imageView_back).setOnClickListener(this);

    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {
        Intent intent = getIntent();
        mMode = intent.getStringExtra(Constant.INTENT_KEY.TYPE);
        if (mMode.equals(Constant.TYPE.ALLORDER)) {
            mData = (SendOrder) intent.getSerializableExtra(Constant.INTENT_KEY.ORDER_DETAIL);

        } else if (mMode.equals(Constant.TYPE.APPOINTEDORDER)) {
            mData = (SendOrder) intent.getSerializableExtra(Constant.INTENT_KEY.ORDER_DETAIL);

        }


    }

    @Override
    protected void findID() {
        mTv_time = (TextView) findViewById(R.id.textView_time);
        mTv_state = (TextView) findViewById(R.id.textView_OrderState);
        mTv_start = (TextView) findViewById(R.id.textView_start);
        mTv_end = (TextView) findViewById(R.id.textView_end);
        mTv_fee = (TextView) findViewById(R.id.textView_fee);
        mTv_fee_money = (TextView) findViewById(R.id.textView_fee_money);
        mTv_finalprice = (TextView) findViewById(R.id.textView_price);
        mTv_pingjia = (TextView) findViewById(R.id.tv_pingjia_content);
        mTv_orderId = (TextView) findViewById(R.id.textView_orderId);

        mRatingbar_pingfeng = (SimpleRatingBar) findViewById(R.id.ratingbar_pingfeng_complete);

        mLine_pingjia = (LinearLayout) findViewById(R.id.line_pingjia);
        mLine_price = (LinearLayout) findViewById(R.id.line_price);
        mLine_pingjia_content = (LinearLayout) findViewById(R.id.line_pingjia_content);
        mTv_no_pingjia = (TextView) findViewById(R.id.tv_no_pingjia);


        mLine_cancel_cause = findViewById(R.id.line_cancel_cause);
        mTv_cancel_cause = (TextView) findViewById(R.id.tv_cancel_cause);
        mTv_order_mileage = (TextView) findViewById(R.id.tv_order_mileage);
        mTv_order_mileage_money = (TextView) findViewById(R.id.tv_order_mileage_money);
        mTv_order_waiting_time = (TextView) findViewById(R.id.tv_order_waiting_time);
        mTv_order_waiting_time_money = (TextView) findViewById(R.id.tv_order_waiting_time_money);
        mTv_comfirm_toll_money = (TextView) findViewById(R.id.tv_comfirm_toll_money);
        mTv_order_other_money = (TextView) findViewById(R.id.tv_order_other_money);


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageView_back:
                finishTo();
                break;


        }
    }
}
